package com.thoughtworks.collection;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.*;

public class CollectionOperator {
    public List<Integer> getListByInterval(int left, int right) {
        ArrayList<Integer> list = new ArrayList<>();
        for (Integer i = left; i <=right ; i++) {
            list.add(i);
        }
        list.sort(Comparator.naturalOrder());
        return list;
    }

    public List<Integer> getEvenListByIntervals(int left, int right) {
        ArrayList<Integer> list = new ArrayList<>();
        for (Integer i = left; i <=right ; i++) {
            if (i%2 == 0){
                list.add(i);
            }
        }
        return list;
    }

    public List<Integer> popEvenElments(int[] array) {
        ArrayList<Integer> list = new ArrayList<>();
        for (Integer m:array) {
            if (m%2 == 0){
                list.add(m);
            }
        }
        return list;
    }

    public int popLastElment(int[] array) {
        ArrayList<Integer> list = new ArrayList<>();
         Integer length = array.length;
        for (Integer m:array) {
            list.add(m);
        }
        return list.get(length-1);
    }

    public List<Integer> popCommonElement(int[] firstArray, int[] secondArray) {
        ArrayList<Integer> list1 = new ArrayList<>();
        ArrayList<Integer> list2 = new ArrayList<>();
        for (Integer a:firstArray) {
            list1.add(a);
        }
        for (Integer b:secondArray) {
            list2.add(b);
        }
        list1.retainAll(list2);
         return list1;
    }

    public List<Integer> addUncommonElement(Integer[] firstArray, Integer[] secondArray) {
        ArrayList<Integer> list1 = new ArrayList<>();
        ArrayList<Integer> list2 = new ArrayList<>();
        ArrayList<Integer> list3 = new ArrayList<>();
        for (Integer a : firstArray) {
            list1.add(a);
        }
        for (Integer b : secondArray) {
            list2.add(b);
        }
        list3.addAll(list1);
        list1.retainAll(list2);
        list2.removeAll(list1);
        list3.addAll(list2);


        return list3;
    }
}
